package cg.studio.distribute.vote.server;

import cg.studio.distribute.vote.model.Topic;
import cg.studio.distribute.vote.site.Site;

public class TypicalServer implements Server
{
  private volatile int[] totalVote = new int[ Topic.values().length ];
  
  public int[] getTotalVote()
  {
    return totalVote.clone();
  }
  
  public void syncPeriodVote()
  {
    int[] totalVoteCopy = totalVote.clone();
    Site[] sites = VoteManager.getSiteAssigner().getSites();
    for( Site site : sites )
    {
      int[] periodVote = site.getPeriodVote();
      if( periodVote != null )
      {
        for( int i=0; i<periodVote.length; ++i )
          totalVoteCopy[i] += periodVote[i];
      }
    }
    
    totalVote = totalVoteCopy.clone();
  }
}
